package org.zeroes.Components;

import com.larvalabs.svgandroid.*;
import org.zeroes.Events.*;
public class ZSBehavior extends ZSComponent {
	public static final int LINEAR=0;
	public static final int EASE_IN=1;
	public static final int EASE_OUT=2;
	public static final int EASE_IN_OUT=3;
	public static final int BACK_IN=4;
	public static final int BACK_OUT=5;
	public static final int ELASTIC_IN=6;
	public static final int ELASTIC_OUT=7;
	public static final int BOUNCE=8;
	public ZSCondition mainCondition;
	public ZSBehavior(String name,ZSSingle<?> subject){
		
		super(name,null,new ZSLogicUnit(){
			
			
			public void is(ZSComponent c,ZSLUParameters p){
		
			//	c.AddProperty("*.property.Subject", p.getParamAtIndex(0));
				
			}
		});
		 this.AddProperty("*.property.Subject", subject);
		
	}
	
	public static float easein(float n){
		return (float)Math.pow((double)n,(double) 1.7f);
	}
	public static float easeout(float n){
		return (float)Math.pow((double)n,(double) 0.48f);
	}
	public static float easeinout(float n){
		
		float q = .48f - n / 1.04f,
                Q = (float)Math.sqrt(.1734f + q * q),
                x = Q - q,
                X =(float)Math.pow(Math.abs(x), 1 / 3) * (x < 0 ? -1 : 1),
                y = -Q - q,
                Y = (float)Math.pow(Math.abs(y), 1 / 3) * (y < 0 ? -1 : 1),
                t = X + Y + .5f;
            return (1 - t) * 3 * t * t + t * t * t;
	}
	public static float backin(float n){
        float s = 1.70158f;
        return n * n * ((s + 1) * n - s);
	}
	public static float backout(float n){
		if(n==0) return 0;
		if(n==1) return 1;
        n = n - 1;
        float s = 1.70158f;
        return n * n * ((s + 1) * n + s) + 1;
	}
	public static float elastic(float n){
		return (float)(Math.pow(2, -10 * n) * Math.sin((n - .075f) * (2 * Math.PI) / .3f) + 1);
	}
	public static float elasticin(float n,float d){
		final float p = d * 0.3f;
		final float s = p / 4;

		final float t = n - 1;
		return -(float)Math.pow(2, 10 * t) * (float)Math.sin((t * d - s) * (2 * Math.PI) / p);
	}
	public static float elasticout(float n,float d){
		if(n==0) return 0;
		if(n==1) return 1;
		final float p = d * 0.3f;
		final float s = p / 4;

		return 1 + (float)Math.pow(2, -10 * n) * (float)Math.sin((n * d - s) * (2 * Math.PI) / p);
	}
	public static float bounce(float n){
		float s = 7.5625f,
                p = 2.75f,
                l;
            if (n < (1 / p)) {
                l = s * n * n;
            } else {
                if (n < (2 / p)) {
                    n -= (1.5 / p);
                    l = s * n * n + .75f;
                } else {
                    if (n < (2.5 / p)) {
                        n -= (2.25 / p);
                        l = s * n * n + .9375f;
                    } else {
                        n -= (2.625 / p);
                        l = s * n * n + .984375f;
                    }
                }
            }
            return l;
	}
	
	public static float cubicin(float n){
		return (float)n * n * n;
	}
	public static float cubicout( float pPercentage) {
		 float t = pPercentage - 1;
		return (float) (1 + (t * t * t));
	}
	public static float cubicinout( float percentage, float pDuration) {
		

		if(percentage < 0.5f) {
			return (float)0.5f * cubicin(2 * percentage);
		} else {
			return (float)(0.5f + 0.5f * cubicout(percentage * 2 - 1));
		}
	}
	
	public void stopMe(){
		if(this.mainCondition!=null)
		this.mainCondition.stoped=true;
	}
	
	public void pauseMe(){
		if(this.mainCondition!=null)
		this.mainCondition.paused=true;
	}
	public void resume(){
		if(this.mainCondition!=null)
		this.mainCondition.paused=false;
	}
}
